@echo off

cd ..\tools

IF EXIST ..\t113-bootloader\rtthread.bin (
    copy ..\t113-bootloader\rtthread.bin rtthread.bin
) ELSE (
    echo bootloader file not exist!
    exit
)

copy ..\t113-spl\sunxi-spl.bin sunxi-spl.bin
:: 将SPL与bootloader合并
mkimage.exe -A arm -O u-boot -T firmware -C none -a 0x42000000 -e 0x42000000 -n 'RT-Thread' -d rtthread.bin rtthread.uimg
dd.exe if=sunxi-spl.bin of=rtt-with-spl.bin
dd.exe if=rtthread.uimg of=rtt-with-spl.bin bs=1024 seek=32 conv=notrunc
del rtthread.uimg

copy rtt-with-spl.bin bootloader.bin
rt_partition_tool_cli\rt_partition_tool_cli.exe bootloader.bin partition_config_16M.yml --pad 393120
copy bootloader.bin .\boot-with-pt16M_UART2.bin
del bootloader.bin

del rtt-with-spl.bin
del rtthread.bin
del sunxi-spl.bin

cd ..\t113-bootloader
